// Copyright (C) 2020 Focus Media Holding Ltd. All Rights Reserved.

package cn.pacerx.running.db.mybatis;

import org.apache.ibatis.ognl.OgnlRuntime;
import org.apache.ibatis.scripting.xmltags.DynamicContext;

import lombok.SneakyThrows;
import lombok.experimental.UtilityClass;

/**
 * 向 mybatis ognl 上下文注入一些工具方法.
 *
 * @see MybatisOgnlUtils
 *
 */
@UtilityClass
public class MybatisOgnlHelper {
    /**
     * 向 mybatis ognl 上下文注入一些工具方法
     */
    @SneakyThrows(ClassNotFoundException.class)
    public static void injectUtils() {
        Class<?> contextMapClass = Class.forName(DynamicContext.class.getName() + "$ContextMap");
        OgnlRuntime.setMethodAccessor(contextMapClass, new ContextMethodAccessor());
    }
}
